package net.niufei.study.cpatterns.activeobject;

public class Scheduler extends Thread {
	private final ActivationQueue queue;

	public Scheduler(ActivationQueue queue) {
		this.queue = queue;
		start();
	}
	
	
	public void invoke(Request request) {
		try {
			queue.putRequest(request);
		} catch (InterruptedException e) {}
	}
	
	
	@Override
	public void run() {
		try {
			while(true) {
				Request request = queue.takeRequest();
				request.execute();
			} 
		}
		catch (InterruptedException e) {}
	}

	
}
